﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

using System.IO;
using H2.NET.Data.Exceller;



namespace H2.NET.Web.Pages
{
    public partial class PMDM : TaskPage
    {
        #region 属性 Public

        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }

        public string Key
        {
            get
            {
                return ViewState["Key"] == null ? "" : (string)ViewState["Key"];

            }
            set { ViewState["Key"] = value; }
        }

        private string[] Sales_To_Party
        {
            get
            {
                if (StoreAPI["Sales_To_Party~" + Key] == null)
                {

                    IList<m_ListPrice_SalesOffice> dlts = (m_ListPrice_SalesOffice.status == "1").List<m_ListPrice_SalesOffice>();
                    string[] sales_office = new string[dlts.Count + 1];

                    sales_office[0] = "";
                    for (int i = 0; i < dlts.Count; i++)
                    {
                        sales_office[i + 1] = dlts[i].Sales_Office;
                    }

                    StoreAPI["Sales_To_Party~" + Key] = sales_office;
                }

                return (string[])StoreAPI["Sales_To_Party~" + Key];
            }
        }

        #endregion

        #region 事件 Page_Load(页面加载)
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;

                //InitDropDownList();
                
                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    VD.Checked = true;
 
                }
                #endregion

                #region 审批环节
                else
                {
                    #region 加载数据并显示
                    mdm_MaterialDetermination material = (mdm_MaterialDetermination.process == TaskAPI.Process & mdm_MaterialDetermination.incident == TaskAPI.Incident).ListFirst<mdm_MaterialDetermination>();
                    if (material != null)
                    {
                        ApplicationNo.Text                  = material.ApplicationNo;
                        VD.Checked                          = material.VD_Checked == "1";
                        SA.Checked                          = material.SA_Checked == "1";
                        SA2.Checked                         = material.SA2_Checked == "1";
                        SA3.Checked                         = material.SA3_Checked == "1";
                        SA4.Checked = material.SA4_Checked == "1";
                        VD_Category.SelectedValue           = material.VD_Category;
                        DrpPriority.SelectedValue = material.DrpPriority;
                        DMO_DrpPriority.SelectedValue = material.DMO_DrpPriority;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            National_Condition_Type.Text = material.National_Condition_Type;
                            National_Sorg_DC.Checked = material.National_Sorg_DC == "1"; ;
                            National_Sales_Organization.Text = material.National_Sales_Organization;
                            Distribution_Channel.Text = material.Distribution_Channel;
                        }
                        National_Division.SelectedValue = material.National_Division;
                        National_Valid_From.Text = material.National_Valid_From;
                        National_Valid_To.Text = material.National_Valid_To;
                        National_Proposed_Reason.Text = material.National_Proposed_Reason;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            City_Condition_Type.Text = material.City_Condition_Type;
                            City_Sorg_DC.Checked = material.City_Sorg_DC == "1";
                            City_Sales_Organization.Text = material.City_Sales_Organization;
                            City_Channel.Text = material.City_Channel;
                        }
                        City_Division.SelectedValue = material.City_Division;
                        City_Valid_From.Text = material.City_Valid_From;
                        City_Valid_To.Text = material.City_Valid_To;
                        City_Proposed_Reason.Text = material.City_Proposed_Reason;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            Sold_Condition_Type.Text = material.Sold_Condition_Type;
                            Sold_Sorg_DC.Checked = material.Sold_Sorg_DC == "1";
                            Sold_Sales_Organization.Text = material.Sold_Sales_Organization;
                            Sold_Channel.Text = material.Sold_Channel;
                        }
                        Sold_Division.SelectedValue = material.Sold_Division;
                        Sold_Valid_From.Text = material.Sold_Valid_From;
                        Sold_Valid_To.Text = material.Sold_Valid_To;
                        Sold_Proposed_Reason.Text = material.Sold_Proposed_Reason;

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            Sales_Condition_Type.Text = material.Sales_Condition_Type;
                            Sales_Sorg_DC.Checked = material.Sales_Sorg_DC == "1";
                            Sales_Sales_Organization.Text = material.Sales_Sales_Organization;
                            Sales_Channel.Text = material.Sales_Channel;
                        }
                        Sales_Division.SelectedValue = material.Sales_Division;
                        Sales_Valid_From.Text = material.Sales_Valid_From;
                        Sales_Valid_To.Text = material.Sales_Valid_To;
                        Sales_Proposed_Reason.Text = material.Sales_Proposed_Reason;
                        All_City.Checked = material.All_City == "1";
                        Some_City.Checked = material.Some_City == "1";

                        if (!(TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit))
                        {
                            Region_Condition_Type.Text = material.Region_Condition_Type;
                            Region_Sorg_DC.Checked = material.Region_Sorg_DC == "1";
                            Region_Sales_Organization.Text = material.Region_Sales_Organization;
                            Region_Channel.Text = material.Region_Channel;
                        }
                        Region_Division.SelectedValue = material.Region_Division;
                        Region_Valid_From.Text = material.Region_Valid_From;
                        Region_Valid_To.Text = material.Region_Valid_To;
                        Region_Proposed_Reason.Text = material.Region_Proposed_Reason;

                        
                      
                    }
                    #endregion

                    #region 审批项初始化
                    switch (TaskAPI.Step)
                    {
                        case "DMO Approve":
                        case "DMO Maintain":
                        case "DMO Check":
                            Assessment1.Option.Add(new t_AssessmentOption("Finish", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;
                        case "Marketing Manager":
                            Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Return", "2", false));
                            break;


                    }
                    #endregion
                }
                #endregion

                #region 设置控件禁启用
                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;

                SetEnable(flg, VD_Category,DrpPriority, VD, SA, SA2, SA3, SA4, All_City, Some_City, National_Division, National_Valid_From, National_Valid_To, National_Proposed_Reason, City_Division, City_Valid_From, City_Valid_To, City_Proposed_Reason, Sold_Division, Sold_Valid_From, Sold_Valid_To, Sold_Proposed_Reason, Sales_Division, Sales_Valid_From, Sales_Valid_To, Sales_Proposed_Reason, Region_Division, Region_Valid_From, Region_Valid_To, Region_Proposed_Reason);
                //SetEnable(TaskAPI.Step == "DMO Maintain", SAP_Code);
                SetEnable(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", DMO_DrpPriority);
                SetVisible(TaskAPI.Step == "DMO Approve" | TaskAPI.Step == "DMO Maintain" | TaskAPI.Step == "DMO Check", P_DMO);
                SetVisible(flg, National_Add, City_Add, Sold_Add, Sales_Add, National_Delete, City_Delete, Sold_Delete, Sales_Delete,Region_Add,Region_Delete);
                Assessment1.Enable = TaskAPI.IsAllowSubmit;
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);

                
                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                InitTabs();
                #endregion

                #region 加深颜色
                string item = null;
                string value = null;
                foreach (Control cr in this.Controls)
                {
                    if (cr is DropDownList)
                    {
                        DropDownList tb = (DropDownList)cr;
                        if (!tb.Enabled)
                        {
                            tb.Enabled = true;
                            item = tb.SelectedItem.Text;
                            value = tb.SelectedValue.ToString();
                            tb.Items.Clear();
                            tb.Items.Add(new ListItem(item, value));
                        }
                        tb.ForeColor = System.Drawing.Color.DimGray;
                    }
                }
                if (!flg || !TaskAPI.IsAllowSubmit)
                {

                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_VD.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA2.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                    foreach (Control cr in P_SA3.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA3.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P_SA4.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                item = tb.SelectedItem.Text;
                                value = tb.SelectedValue.ToString();
                                tb.Items.Clear();
                                tb.Items.Add(new ListItem(item, value));
                            }
                            tb.ForeColor = System.Drawing.Color.DimGray;
                        }
                    }
                    foreach (Control cr in P_SA4.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                }

                #endregion
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            InitControls();
            base.OnLoad(e);
        }

        public void InitControls()
        {
            bool flg = TaskAPI.IsAllowSubmit && TaskAPI.IsBeginStep;

            gv_National.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_National.DynamicColumn.Add(new BoundColumn2("01", "Material From", BoundColumnType2.TextBox, 90, Align.Left, flg, "National_Material_From", InputType.None, null));
            gv_National.DynamicColumn.Add(new BoundColumn2("02", "Name", BoundColumnType2.TextBox, 100, Align.Left, flg, "National_Name", InputType.None, null));
            gv_National.DynamicColumn.Add(new BoundColumn2("03", "Material To", BoundColumnType2.TextBox, 90, Align.Left, flg, "National_Material_To", InputType.None, null));
            gv_National.DynamicColumn.Add(new BoundColumn2("04", "Description", BoundColumnType2.TextBox, 100, Align.Left, flg, "National_Description", InputType.None, null));
            gv_National.DynamicColumn.Add(new BoundColumn2("05", "Uom", BoundColumnType2.Label, 40, Align.Left, flg, "National_Uom", InputType.None, null));
            gv_National.DynamicColumn.Add(new BoundColumn2("06", "Reason", BoundColumnType2.Label, 70, Align.Left, flg, "National_Reason", InputType.None, null));
            gv_National.DynamicColumn.Add(new BoundColumn2("07", "Alternative Materials", BoundColumnType2.TextBox,120, Align.Left, flg, "National_Alternative_Materials", InputType.None, null));

            gv_City.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("01", "City Name", BoundColumnType2.TextBox, 40, Align.Left, flg, "City_Name", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("02", "City Code", BoundColumnType2.TextBox, 40, Align.Left, flg, "City_Code", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("03", "Material From", BoundColumnType2.TextBox, 90, Align.Left, flg, "City_Material_From", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("04", "Name", BoundColumnType2.TextBox, 100, Align.Left, flg, "City_Name2", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("05", "Material To", BoundColumnType2.TextBox, 90, Align.Left, flg, "City_Material_To", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("06", "Description", BoundColumnType2.TextBox, 100, Align.Left, flg, "City_Description", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("07", "Uom", BoundColumnType2.Label, 40, Align.Left, flg, "City_Uom", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("08", "Reason", BoundColumnType2.Label, 70, Align.Left, flg, "City_Reason", InputType.None, null));
            gv_City.DynamicColumn.Add(new BoundColumn2("09", "Alternative Materials", BoundColumnType2.TextBox, 120, Align.Left, flg, "City_Alternative_Materials", InputType.None, null));

            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("01", "Sold-to party", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sold_To_Party", InputType.None, null));
            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("02", "Material From", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sold_Material_From", InputType.None, null));
            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("03", "Name", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sold_Name", InputType.None, null));
            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("04", "Material To", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sold_Material_To", InputType.None, null));
            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("05", "Description", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sold_Description", InputType.None, null));
            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("06", "Uom", BoundColumnType2.Label, 40, Align.Left, flg, "Sold_Uom", InputType.None, null));
            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("07", "Reason", BoundColumnType2.Label, 70, Align.Left, flg, "Sold_Reason", InputType.None, null));
            gv_SoldTo.DynamicColumn.Add(new BoundColumn2("08", "Alternative Materials", BoundColumnType2.TextBox,100, Align.Left, flg, "Sold_Alternative_Materials", InputType.None, null));

            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("01", "Sales Office", BoundColumnType2.DropDownList, 50, Align.Left, flg, "Sales_To_Party", InputType.None, Sales_To_Party));
            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("02", "Material From", BoundColumnType2.TextBox, 90, Align.Left, flg, "Sales_Material_From", InputType.None, null));
            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("03", "Name", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sales_Name", InputType.None, null));
            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("04", "Material To", BoundColumnType2.TextBox, 90, Align.Left, flg, "Sales_Material_To", InputType.None, null));
            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("05", "Description", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sales_Description", InputType.None, null));
            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("06", "Uom", BoundColumnType2.Label, 40, Align.Left, flg, "Sales_Uom", InputType.None, null));
            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("07", "Reason", BoundColumnType2.Label, 70, Align.Left, flg, "Sales_Reason", InputType.None, null));
            gv_SalesOffice.DynamicColumn.Add(new BoundColumn2("08", "Alternative Materials", BoundColumnType2.TextBox, 100, Align.Left, flg, "Sales_Alternative_Materials", InputType.None, null));

            gv_Region.DynamicColumn.Add(new BoundColumn2("00", "No", BoundColumnType2.Label, 0, Align.Left, false, "No", InputType.None, null));
            gv_Region.DynamicColumn.Add(new BoundColumn2("01", "Region", BoundColumnType2.TextBox, 100, Align.Left, flg, "Region", InputType.None, null));
            gv_Region.DynamicColumn.Add(new BoundColumn2("02", "Material From", BoundColumnType2.TextBox, 90, Align.Left, flg, "Region_Material_From", InputType.None, null));
            gv_Region.DynamicColumn.Add(new BoundColumn2("03", "Name", BoundColumnType2.TextBox, 100, Align.Left, flg, "Region_Name", InputType.None, null));
            gv_Region.DynamicColumn.Add(new BoundColumn2("04", "Material To", BoundColumnType2.TextBox, 90, Align.Left, flg, "Region_Material_To", InputType.None, null));
            gv_Region.DynamicColumn.Add(new BoundColumn2("05", "Description", BoundColumnType2.TextBox, 100, Align.Left, flg, "Region_Description", InputType.None, null));
            gv_Region.DynamicColumn.Add(new BoundColumn2("06", "Uom", BoundColumnType2.Label, 40, Align.Left, flg, "Region_Uom", InputType.None, null));
            gv_Region.DynamicColumn.Add(new BoundColumn2("07", "Reason", BoundColumnType2.Label, 70, Align.Left, flg, "Region_Reason", InputType.None, null));
            gv_Region.DynamicColumn.Add(new BoundColumn2("08", "Alternative Materials", BoundColumnType2.TextBox, 100, Align.Left, flg, "Region_Alternative_Materials", InputType.None, null));

            
            
            
            if (!Page.IsPostBack)
            {
                gv_National.Key = Key;
                gv_City.Key = Key;
                gv_SoldTo.Key = Key;
                gv_SalesOffice.Key = Key;
                gv_Region.Key = Key;


              

                #region 发起步骤
                if (TaskAPI.IsInitiate)
                {
                    List<mdm_National_Gridview> national_s = new List<mdm_National_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        national_s.Add(new mdm_National_Gridview());
                        national_s[i].No = i + 1;
                    }
                    gv_National.DataSource = national_s;

                    List<mdm_City_Gridview> city_s = new List<mdm_City_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        city_s.Add(new mdm_City_Gridview());
                        city_s[i].No = i + 1;
                    }
                    gv_City.DataSource = city_s;

                    List<mdm_Sold_Gridview> sold_s = new List<mdm_Sold_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sold_s.Add(new mdm_Sold_Gridview());
                        sold_s[i].No = i + 1;
                    }
                    gv_SoldTo.DataSource = sold_s;

                    List<mdm_Sales_Gridview> sales_s = new List<mdm_Sales_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        sales_s.Add(new mdm_Sales_Gridview());
                        sales_s[i].No = i + 1;
                    }
                    gv_SalesOffice.DataSource = sales_s;

                    List<mdm_Regoion_Gridview> region_s = new List<mdm_Regoion_Gridview>();
                    for (int i = 0; i < 5; i++)
                    {
                        region_s.Add(new mdm_Regoion_Gridview());
                        region_s[i].No = i + 1;
                    }
                    gv_Region.DataSource = region_s;



                }
                #endregion

                #region 审批环节
                else
                {
                    IList<mdm_National_Gridview> national_s = (mdm_National_Gridview.process == TaskAPI.Process & mdm_National_Gridview.incident == TaskAPI.Incident).List<mdm_National_Gridview>();
                    if (national_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            national_s.Add(new mdm_National_Gridview());
                            national_s[i].No = i + 1;
                        }
                    }
                    gv_National.DataSource = national_s;
                    


                    IList<mdm_City_Gridview> city_s = (mdm_City_Gridview.process == TaskAPI.Process & mdm_City_Gridview.incident == TaskAPI.Incident).List<mdm_City_Gridview>();
                    if (city_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            city_s.Add(new mdm_City_Gridview());
                            city_s[i].No = i + 1;
                        }
                    }
                    gv_City.DataSource = city_s;

                    IList<mdm_Sold_Gridview> sold_s = (mdm_Sold_Gridview.process == TaskAPI.Process & mdm_Sold_Gridview.incident == TaskAPI.Incident).List<mdm_Sold_Gridview>();
                    if (sold_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sold_s.Add(new mdm_Sold_Gridview());
                            sold_s[i].No = i + 1;
                        }
                    }
                    gv_SoldTo.DataSource = sold_s;

                    IList<mdm_Sales_Gridview> sales_s = (mdm_Sales_Gridview.process == TaskAPI.Process & mdm_Sales_Gridview.incident == TaskAPI.Incident).List<mdm_Sales_Gridview>();
                    if (sales_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            sales_s.Add(new mdm_Sales_Gridview());
                            sales_s[i].No = i + 1;
                        }
                    }
                    gv_SalesOffice.DataSource = sales_s;

                    IList<mdm_Regoion_Gridview> region_s = (mdm_Regoion_Gridview.process == TaskAPI.Process & mdm_Regoion_Gridview.incident == TaskAPI.Incident).List<mdm_Regoion_Gridview>();
                    if (region_s.Count == 0)
                    {
                        for (int i = 0; i < 5; i++)
                        {
                            region_s.Add(new mdm_Regoion_Gridview());
                            region_s[i].No = i + 1;
                        }
                    }
                    gv_Region.DataSource = region_s;
                }
                #endregion
            }
            //SetVisible(flg, SEFI_1_Add, SEFI_2_Add);
        }
        #endregion  
        
        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text        = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName          = UserAPI.UserName;
                        TaskAPI["ApplicationNo"]  = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"]     = UserAPI.UserName;
                        TaskAPI["Time"]           = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"]     = UserAPI.Department;
                        TaskAPI["ServerName"] = Util.AppSettings("ServerName");
                    }
                    
                    TaskAPI.Summary = (VD_Category.SelectedItem.Text.Split(',').Length >= 2 ? VD_Category.SelectedItem.Text.Split(',')[1].Trim() : VD_Category.Text)
                                    + " / " + ApplicationNo.Text + (VD.Checked ? " / By National " : "") + (SA.Checked ? " / By Ctiy " : "") + (SA2.Checked ? " / By Sold-to " : "") + (SA3.Checked ? " / By Sales Office " : "") + (SA4.Checked ? " / By Region " : "");

                    TaskAPI["Actions"]        = VD_Category.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;
                    TaskAPI["DrpPriority"] = DrpPriority.SelectedItem.Text;

                    #region 从数据库取得流程步骤处理人
                    SortedList<string, string> rec_a = new SortedList<string, string>();

                    IList<mdc_Recipient> rec_s = (mdc_Recipient.process == TaskAPI.Process & (mdc_Recipient.distribute == VD_Category.SelectedValue | mdc_Recipient.distribute == "*") & mdc_Recipient.status == 1).List<mdc_Recipient>();
                    foreach (mdc_Recipient rec in rec_s)
                    {
                        if (!rec_a.ContainsKey(rec.Step))
                        {
                            rec_a.Add(rec.Step, rec.Recipient);
                            continue;
                        }

                        if (rec_a.Values[rec_a.IndexOfKey(rec.Step)].Contains(rec.Recipient))
                        {
                            continue;
                        }

                        rec_a[rec.Step] = rec_a.Values[rec_a.IndexOfKey(rec.Step)] + "," + rec.Recipient;
                    }

                    //步骤处理人赋值
                    for (int i = 0; i < rec_a.Keys.Count; i++)
                    {
                        TaskAPI["R_" + rec_a.Keys[i].Replace(" ", "_")] = rec_a.Values[i].Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                    }

                    m_OrgChart oc = (m_OrgChart.empID.In(m_OrgChart.supervisorEmpID, m_OrgChart.winID == UserAPI.UserName)).ListFirst<m_OrgChart>();
                    if (oc != null)
                    {
                        TaskAPI["R_Marketing_Manager"] = oc.WinID;
                    }

                   

                    #endregion
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;
                }

               

              

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        mdm_MaterialDetermination material = new mdm_MaterialDetermination();
                        if ((mdm_MaterialDetermination.process == TaskAPI.Process & mdm_MaterialDetermination.incident == TaskAPI.Incident & mdm_MaterialDetermination.userName == UserAPI.UserName).Count<mdm_MaterialDetermination>() > 0)
                        {
                            material = (mdm_MaterialDetermination.process == TaskAPI.Process & mdm_MaterialDetermination.incident == TaskAPI.Incident & mdm_MaterialDetermination.userName == UserAPI.UserName).ListFirst<mdm_MaterialDetermination>();
                        }
                        else
                        {
                            material.Process = TaskAPI.Process;
                            material.Incident = TaskAPI.Incident;
                            material.UserName = UserAPI.UserName;
                            material.UserFullName = UserAPI.UserFullName;
                            material.ApplicationNo = ApplicationNo.Text;
                            material.Time = System.DateTime.Now;
                            material.Status = 0;
                            material.Department = UserAPI.Department;
                        }

                        material.VD_Category       = VD_Category.SelectedValue;
                        material.DrpPriority = DrpPriority.SelectedValue;
                        material.VD_Checked        = VD.Checked ? "1" : "0";
                        material.SA_Checked        = SA.Checked ? "1" : "0";
                        material.SA2_Checked       = SA2.Checked ? "1" : "0";
                        material.SA3_Checked = SA3.Checked ? "1" : "0";
                        material.SA4_Checked = SA4.Checked ? "1" : "0";
                      
                        #region VD
                        if (VD.Checked)
                        {
                            material.National_Condition_Type        = National_Condition_Type.Text;
                            material.National_Sorg_DC               = National_Sorg_DC.Checked ? "1" : "0";
                            material.National_Sales_Organization    = National_Sales_Organization.Text;
                            material.Distribution_Channel           = Distribution_Channel.Text;
                            material.National_Division              = National_Division.SelectedValue;
                            material.National_Valid_From            = National_Valid_From.Text;
                            material.National_Valid_To              = National_Valid_To.Text;
                            material.National_Proposed_Reason       = National_Proposed_Reason.Text; 
                        }
                        #endregion

                        #region SA
                        if (SA.Checked)
                        {
                            material.City_Condition_Type            = City_Condition_Type.Text;
                            material.City_Sorg_DC                   = City_Sorg_DC.Checked ? "1" : "0";
                            material.City_Sales_Organization        = City_Sales_Organization.Text;
                            material.City_Channel                   = City_Channel.Text;
                            material.City_Division                  = City_Division.SelectedValue;
                            material.City_Valid_From                = City_Valid_From.Text;
                            material.City_Valid_To                  = City_Valid_To.Text;
                            material.City_Proposed_Reason           = City_Proposed_Reason.Text;
                            material.All_City = All_City.Checked ? "1" : "0";
                            material.Some_City = Some_City.Checked ? "1" : "0";
                        }
                        #endregion

                        #region SA2
                        if (SA2.Checked)
                        {
                            material.Sold_Condition_Type            = Sold_Condition_Type.Text;
                            material.Sold_Sorg_DC                   = Sold_Sorg_DC.Checked ? "1" : "0";
                            material.Sold_Sales_Organization        = Sold_Sales_Organization.Text;
                            material.Sold_Channel                   = Sold_Channel.Text;
                            material.Sold_Division                  = Sold_Division.SelectedValue;
                            material.Sold_Valid_From                = Sold_Valid_From.Text;
                            material.Sold_Valid_To                  = Sold_Valid_To.Text;
                            material.Sold_Proposed_Reason           = Sold_Proposed_Reason.Text;

                        }
                        #endregion

                        #region SA3
                        if (SA3.Checked)
                        {
                            material.Sales_Condition_Type           = Sales_Condition_Type.Text;
                            material.Sales_Sorg_DC                  = Sales_Sorg_DC.Checked ? "1" : "0";
                            material.Sales_Sales_Organization       = Sales_Sales_Organization.Text;
                            material.Sales_Channel                  = Sales_Channel.Text;
                            material.Sales_Division                 = Sales_Division.SelectedValue;
                            material.Sales_Valid_From               = Sales_Valid_From.Text;
                            material.Sales_Valid_To                 = Sales_Valid_To.Text;
                            material.Sales_Proposed_Reason          = Sales_Proposed_Reason.Text;

                        }
                        #endregion

                        #region SA4
                        if (SA4.Checked)
                        {
                            material.Region_Condition_Type = Region_Condition_Type.Text;
                            material.Region_Sorg_DC = Region_Sorg_DC.Checked ? "1" : "0";
                            material.Region_Sales_Organization = Region_Sales_Organization.Text;
                            material.Region_Channel = Region_Channel.Text;
                            material.Region_Division = Region_Division.SelectedValue;
                            material.Region_Valid_From = Region_Valid_From.Text;
                            material.Region_Valid_To = Region_Valid_To.Text;
                            material.Region_Proposed_Reason = Region_Proposed_Reason.Text;

                        }
                        #endregion

                        
                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, material);
                    }
                    #endregion

                    Save();
                    #region Priority功能
                    if (TaskAPI.IsBeginStep && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = new mdc_Priority();
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = new mdc_Priority();
                            pro.Process = TaskAPI.Process;
                            pro.Incident = TaskAPI.Incident;
                            pro.Business_Priority = Convert.ToInt32(DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }

                    }


                    if ((TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check") && !string.IsNullOrEmpty(this.DMO_DrpPriority.SelectedValue) && !string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {

                        //mdc_Priority pro;
                        //pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                        //pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                        //Storage.Save(pro);
                        mdc_Priority pro;
                        if ((mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).Count<mdc_Priority>() > 0)
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }
                        else
                        {
                            pro = (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == TaskAPI.Incident).ListFirst<mdc_Priority>();
                            pro.DMO_Priority = Convert.ToInt32(DMO_DrpPriority.SelectedValue);
                            Storage.Save(pro);
                        }


                    }
                    #endregion

                    #region “DMO Maintain”步骤
                    if (TaskAPI.Step == "DMO Maintain" || TaskAPI.Step == "DMO Approve" || TaskAPI.Step == "DMO Check")
                    {

                        TaskAPI["DMO_DrpPriority"] = DMO_DrpPriority.SelectedItem.Text;
                        (mdm_MaterialDetermination.process == TaskAPI.Process & mdm_MaterialDetermination.incident == TaskAPI.Incident).Edit<mdm_MaterialDetermination>(p =>
                        {
                            // p.SAP_Code = SAP_Code.Text;
                            p.DMO_DrpPriority = DMO_DrpPriority.SelectedValue;

                        }
                        );
                    }
                    #endregion
                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (mdm_MaterialDetermination.process == TaskAPI.Process & mdm_MaterialDetermination.incident == TaskAPI.Incident).Edit<mdm_MaterialDetermination>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见
                    
                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }

                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    if (!string.IsNullOrEmpty(DrpPriority.SelectedValue))
                    {
                        (mdc_Priority.process == TaskAPI.Process & mdc_Priority.incident == 0).Edit<mdc_Priority>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });
                    }
                    
                    (mdm_MaterialDetermination.process == TaskAPI.Process & mdm_MaterialDetermination.incident == 0 & mdm_MaterialDetermination.userName == UserAPI.UserName).Edit<mdm_MaterialDetermination>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.userName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username== UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (mdm_National_Gridview.process == TaskAPI.Process & mdm_National_Gridview.incident == 0 & mdm_National_Gridview.userName == UserAPI.UserName).Edit<mdm_National_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (mdm_City_Gridview.process == TaskAPI.Process & mdm_City_Gridview.incident == 0 & mdm_City_Gridview.userName == UserAPI.UserName).Edit<mdm_City_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (mdm_Sold_Gridview.process == TaskAPI.Process & mdm_Sold_Gridview.incident == 0 & mdm_Sold_Gridview.userName == UserAPI.UserName).Edit<mdm_Sold_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (mdm_Sales_Gridview.process == TaskAPI.Process & mdm_Sales_Gridview.incident == 0 & mdm_Sales_Gridview.userName == UserAPI.UserName).Edit<mdm_Sales_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                    (mdm_Regoion_Gridview.process == TaskAPI.Process & mdm_Regoion_Gridview.incident == 0 & mdm_Regoion_Gridview.userName == UserAPI.UserName).Edit<mdm_Regoion_Gridview>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });
                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 事件 CheckedChanged
        protected void VD_CheckedChanged(object sender, EventArgs e)
        {

            if (!VD.Checked && !SA.Checked && !SA2.Checked && !SA3.Checked && !SA4.Checked)
            {
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('至少保留一个选择项！',false)");
                VD.Checked = true;
            }
            SetVisible(false, P_VD, P_SA, P_SA2, P_SA3,P_SA4);

            switch(((Anthem.CheckBox)sender).ID)
            {
                case "VD":
                    
                    if (VD.Checked)
                    {
                       // SA.Checked = false;
                        //SA2.Checked = false;
                        //SA3.Checked = false;
                    }
                    //VD.Checked = !SA.Checked;
                    //VD.Checked = !SA2.Checked;
                    //VD.Checked = !SA3.Checked;
                    VD_L.Visible = VD.Checked;
                    break;
                
                case "SA":
                    if (SA.Checked)
                    {
                        //VD.Checked = false;
                        //SA2.Checked = false;
                        //SA3.Checked = false;
                    }
                    SA_L.Visible = SA.Checked;
                    //if (!SA.Checked & !SA2.Checked) SA.Checked = true;
                    //SA.Checked = !VD.Checked;
                    //SA.Checked = !SA2.Checked;
                    //SA.Checked = !SA3.Checked;
                    
                    //if (!SA.Checked & SA2.Checked) { SA2_L.CssClass = "tabs1"; Tabs_Click(SA2_L, e); }
                    break;

                case "SA2":

                    if (SA2.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA3.Checked = false;
                    }
                    //SA2.Checked = !SA.Checked;
                    //SA2.Checked = !VD.Checked;
                    //SA2.Checked = !SA3.Checked;
                    SA2_L.Visible = SA2.Checked;
                    break;

                case "SA3":

                    if (SA3.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA2.Checked = false;
                    }
                    //SA3.Checked = !SA.Checked;
                    //SA3.Checked = !VD.Checked;
                    //SA3.Checked = !SA2.Checked;
                    SA3_L.Visible = SA3.Checked;
                    break;

                case "SA4":

                    if (SA4.Checked)
                    {
                        //SA.Checked = false;
                        //VD.Checked = false;
                        //SA2.Checked = false;
                    }
                    //SA3.Checked = !SA.Checked;
                    //SA3.Checked = !VD.Checked;
                    //SA3.Checked = !SA2.Checked;
                    SA4_L.Visible = SA4.Checked;
                    break;
                    
            }
           
         
            InitTabs();
        }
        #endregion

        #region 事件 Category变换
        protected void VD_Category_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetEnable((VD_Category.SelectedValue == "1" || VD_Category.SelectedValue == "2" || VD_Category.SelectedValue == "3"),DrpPriority, All_City,Some_City,National_Division, National_Valid_From, National_Valid_To, National_Proposed_Reason, City_Division, City_Valid_From, City_Valid_To, City_Proposed_Reason, Sold_Division, Sold_Valid_From, Sold_Valid_To, Sold_Proposed_Reason, Sales_Division, Sales_Valid_From, Sales_Valid_To, Sales_Proposed_Reason, Region_Division, Region_Valid_From, Region_Valid_To, Region_Proposed_Reason);
            
        }
        #endregion

        #region 事件 Tabs切换
        protected void Tabs_Click(object sender, EventArgs e)
        {
            if (((LinkButton)sender).CssClass == "tabs2")
            {
                return;
            }

            #region 初始化
            SetVisible(false, P_VD, P_SA, P_SA2, P_SA3,P_SA4);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
            SA3_L.CssClass = "tabs1";
            SA4_L.CssClass = "tabs1";
            #endregion

            #region Tabs切换动作
            switch (((LinkButton)sender).ID)
            {
                case "VD_L":
                    VD_L.CssClass = "tabs2";
                    P_VD.Visible = true;
                    break;
                case "SA_L":
                    SA_L.CssClass = "tabs2";
                    P_SA.Visible = true;
                    break;
                case "SA2_L":
                    SA2_L.CssClass = "tabs2";
                    P_SA2.Visible = true;
                    break;
                case "SA3_L":
                    SA3_L.CssClass = "tabs2";
                    P_SA3.Visible = true;
                    break;
                case "SA4_L":
                    SA4_L.CssClass = "tabs2";
                    P_SA4.Visible = true;
                    break;
            }
            #endregion
        }
        #endregion

        #region 方法 初始化Tabs
        protected void InitTabs()
        {
            VD_L.Visible = VD.Checked;
            SA_L.Visible = SA.Checked;
            SA2_L.Visible = SA2.Checked;
            SA3_L.Visible = SA3.Checked;
            SA4_L.Visible = SA4.Checked;

            SetVisible(false, P_VD, P_SA, P_SA2, P_SA3, P_SA4);
            VD_L.CssClass = "tabs1";
            SA_L.CssClass = "tabs1";
            SA2_L.CssClass = "tabs1";
            SA3_L.CssClass = "tabs1";
            SA4_L.CssClass = "tabs1";

            //默认第1个显示 Tabs被选中
            if (VD_L.Visible)
            {
                VD_L.CssClass = "tabs2";
                P_VD.Visible = true;
                return;
            }

            if (SA_L.Visible)
            {
                SA_L.CssClass = "tabs2";
                P_SA.Visible = true;
                return;
            }

            if (SA2_L.Visible)
            {
                SA2_L.CssClass = "tabs2";
                P_SA2.Visible = true;
                return;
            }

            if (SA3_L.Visible)
            {
                SA3_L.CssClass = "tabs2";
                P_SA3.Visible = true;
                return;
            }
            if (SA4_L.Visible)
            {
                SA4_L.CssClass = "tabs2";
                P_SA4.Visible = true;
                return;
            }

        }
        #endregion

        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                
                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 Save(保存数据库)
        public void Save()
        {
            //if (!Status.IsEdited)
            //{
            //    return;
            //}

            foreach (mdm_National_Gridview national_1 in (List<mdm_National_Gridview>)gv_National.DataSource)
            {
                if (string.IsNullOrEmpty(national_1.National_Material_From) && string.IsNullOrEmpty(national_1.National_Name) && string.IsNullOrEmpty(national_1.National_Description) && string.IsNullOrEmpty(national_1.National_Alternative_Materials))
                {
                    continue;
                }
                national_1.Process = TaskAPI.Process;
                national_1.Incident = TaskAPI.Incident;
                national_1.UserName = UserAPI.UserName;
                national_1.Time = System.DateTime.Now;
                national_1.Status = 0;
                Storage.Save(national_1);
            }

            foreach (mdm_City_Gridview city_1 in (List<mdm_City_Gridview>)gv_City.DataSource)
            {
                if (string.IsNullOrEmpty(city_1.City_Material_From) && string.IsNullOrEmpty(city_1.City_Name2) && string.IsNullOrEmpty(city_1.City_Description) && string.IsNullOrEmpty(city_1.City_Alternative_Materials))
                {
                    continue;
                }

                city_1.Process = TaskAPI.Process;
                city_1.Incident = TaskAPI.Incident;
                city_1.UserName = UserAPI.UserName;
                city_1.Time = System.DateTime.Now;
                city_1.Status = 0;
                Storage.Save(city_1);
            }

            foreach (mdm_Sold_Gridview sold_1 in (List<mdm_Sold_Gridview>)gv_SoldTo.DataSource)
            {
                if (string.IsNullOrEmpty(sold_1.Sold_Material_From) && string.IsNullOrEmpty(sold_1.Sold_Name) && string.IsNullOrEmpty(sold_1.Sold_Description) && string.IsNullOrEmpty(sold_1.Sold_Alternative_Materials))
                {
                    continue;
                }
                sold_1.Process = TaskAPI.Process;
                sold_1.Incident = TaskAPI.Incident;
                sold_1.UserName = UserAPI.UserName;
                sold_1.Time = System.DateTime.Now;
                sold_1.Status = 0;
                Storage.Save(sold_1);
            }

            foreach (mdm_Sales_Gridview sales_1 in (List<mdm_Sales_Gridview>)gv_SalesOffice.DataSource)
            {
                if (string.IsNullOrEmpty(sales_1.Sales_Material_From) && string.IsNullOrEmpty(sales_1.Sales_Name) && string.IsNullOrEmpty(sales_1.Sales_Description) && string.IsNullOrEmpty(sales_1.Sales_Description) && string.IsNullOrEmpty(sales_1.Sales_Alternative_Materials))
                {
                    continue;
                }
                sales_1.Process = TaskAPI.Process;
                sales_1.Incident = TaskAPI.Incident;
                sales_1.UserName = UserAPI.UserName;
                sales_1.Time = System.DateTime.Now;
                sales_1.Status = 0;
                Storage.Save(sales_1);
            }

            foreach (mdm_Regoion_Gridview region_1 in (List<mdm_Regoion_Gridview>)gv_Region.DataSource)
            {
                if (string.IsNullOrEmpty(region_1.Region_Material_From) && string.IsNullOrEmpty(region_1.Region_Name) && string.IsNullOrEmpty(region_1.Region_Description) && string.IsNullOrEmpty(region_1.Region_Alternative_Materials))
                {
                    continue;
                }
                region_1.Process = TaskAPI.Process;
                region_1.Incident = TaskAPI.Incident;
                region_1.UserName = UserAPI.UserName;
                region_1.Time = System.DateTime.Now;
                region_1.Status = 0;
                Storage.Save(region_1);
            }

        }
                    //TaskAPI["Material"] = SEFI_Material;


          #endregion

        #region 事件 Add(增加行)
        protected void Add_Click(object sender, EventArgs e)
        {
            switch (((Anthem.Button)sender).ID)
            {
                case "National_Add":
                    List<mdm_National_Gridview> national_1_s = (List<mdm_National_Gridview>)gv_National.DataSource;
                    mdm_National_Gridview national_1 = new mdm_National_Gridview();
                    national_1.No = national_1_s.Count + 1;
                    national_1_s.Insert(national_1_s.Count, national_1);
                    gv_National.DataSource = national_1_s;
                    gv_National.DataBind();
                    break;

                case "City_Add":
                    List<mdm_City_Gridview> city_1_s = (List<mdm_City_Gridview>)gv_City.DataSource;
                    mdm_City_Gridview city_1 = new mdm_City_Gridview();
                    city_1.No = city_1_s.Count + 1;
                    city_1_s.Insert(city_1_s.Count, city_1);
                    gv_City.DataSource = city_1_s;
                    gv_City.DataBind();
                    break;

                case "Sold_Add":
                    List<mdm_Sold_Gridview> sold_1_s = (List<mdm_Sold_Gridview>)gv_SoldTo.DataSource;
                    mdm_Sold_Gridview sold_1 = new mdm_Sold_Gridview();
                    sold_1.No = sold_1_s.Count + 1;
                    sold_1_s.Insert(sold_1_s.Count, sold_1);
                    gv_SoldTo.DataSource = sold_1_s;
                    gv_SoldTo.DataBind();
                    break;

                case "Sales_Add":
                    List<mdm_Sales_Gridview> sales_1_s = (List<mdm_Sales_Gridview>)gv_SalesOffice.DataSource;
                    mdm_Sales_Gridview sales_1 = new mdm_Sales_Gridview();
                    sales_1.No = sales_1_s.Count + 1;
                    sales_1_s.Insert(sales_1_s.Count, sales_1);
                    gv_SalesOffice.DataSource = sales_1_s;
                    gv_SalesOffice.DataBind();
                    break;

                case "Region_Add":
                    List<mdm_Regoion_Gridview> region_1_s = (List<mdm_Regoion_Gridview>)gv_Region.DataSource;
                    mdm_Regoion_Gridview region_1 = new mdm_Regoion_Gridview();
                    region_1.No = region_1_s.Count + 1;
                    region_1_s.Insert(region_1_s.Count, region_1);
                    gv_Region.DataSource = region_1_s;
                    gv_Region.DataBind();
                    break;
        }
        }
        #endregion

        #region 事件 Delete(删除行)
        protected void Delete_Click(object sender, EventArgs e)
        {
            switch (((Anthem.Button)sender).ID)
            {
                case "National_Delete":
                    //List<mdm_National_Gridview> national_1_s = (List<mdm_National_Gridview>)gv_National.DataSource;
                    //if (national_1_s.Count == 1)
                    //{
                    //    return;
                    //}
                    //national_1_s.RemoveAt(gv_National.ChangedRowIndex == -1 || gv_National.ChangedRowIndex >= national_1_s.Count ? national_1_s.Count - 1 : gv_National.ChangedRowIndex);
                    //gv_National.DataSource = national_1_s;
                    //gv_National.DataBind();
                    //break;

                    List<mdm_National_Gridview> base_1_s = (List<mdm_National_Gridview>)gv_National.DataSource;
                    IList<mdm_National_Gridview> base1 = (mdm_National_Gridview.process == TaskAPI.Process & mdm_National_Gridview.incident == TaskAPI.Incident).List<mdm_National_Gridview>();
                    if (base_1_s.Count == 1)
                    {

                        return;
                    }
                    base_1_s.RemoveAt(gv_National.ChangedRowIndex == -1 || gv_National.ChangedRowIndex >= base_1_s.Count ? base_1_s.Count - 1 : gv_National.ChangedRowIndex);
                    bool flag = false;
                    foreach (mdm_National_Gridview base_1 in base1)
                    {

                        foreach (mdm_National_Gridview base_2 in base_1_s)
                        {
                            if (base_2.ID == base_1.ID)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            Storage.Delete(base_1);
                        }
                        flag = false;
                    }
                    gv_National.DataSource = base_1_s;
                    gv_National.DataBind();
                    break;

                case "City_Delete":
                    //List<mdm_City_Gridview> city_1_s = (List<mdm_City_Gridview>)gv_City.DataSource;
                    //if (city_1_s.Count == 1)
                    //{
                    //    return;
                    //}
                    //city_1_s.RemoveAt(gv_City.ChangedRowIndex == -1 || gv_City.ChangedRowIndex >= city_1_s.Count ? city_1_s.Count - 1 : gv_City.ChangedRowIndex);
                    //gv_City.DataSource = city_1_s;
                    //gv_City.DataBind();
                    //break;
                    List<mdm_City_Gridview> city_1_s = (List<mdm_City_Gridview>)gv_City.DataSource;
                    IList<mdm_City_Gridview> city1 = (mdm_City_Gridview.process == TaskAPI.Process & mdm_City_Gridview.incident == TaskAPI.Incident).List<mdm_City_Gridview>();
                    if (city_1_s.Count == 1)
                    {

                        return;
                    }
                    city_1_s.RemoveAt(gv_City.ChangedRowIndex == -1 || gv_City.ChangedRowIndex >= city_1_s.Count ? city_1_s.Count - 1 : gv_City.ChangedRowIndex);
                    bool flag2 = false;
                    foreach (mdm_City_Gridview city_1 in city1)
                    {

                        foreach (mdm_City_Gridview city_2 in city_1_s)
                        {
                            if (city_2.ID == city_1.ID)
                            {
                                flag2 = true;
                                break;
                            }
                        }
                        if (!flag2)
                        {
                            Storage.Delete(city_1);
                        }
                        flag2 = false;
                    }
                    gv_City.DataSource = city_1_s;
                    gv_City.DataBind();
                    break;

                case "Sold_Delete":
                    //List<mdm_Sold_Gridview> sold_1_s = (List<mdm_Sold_Gridview>)gv_SoldTo.DataSource;
                    //if (sold_1_s.Count == 1)
                    //{
                    //    return;
                    //}
                    //sold_1_s.RemoveAt(gv_SoldTo.ChangedRowIndex == -1 || gv_SoldTo.ChangedRowIndex >= sold_1_s.Count ? sold_1_s.Count - 1 : gv_SoldTo.ChangedRowIndex);
                    //gv_SoldTo.DataSource = sold_1_s;
                    //gv_SoldTo.DataBind();
                    //break;
                    List<mdm_Sold_Gridview> sold_1_s = (List<mdm_Sold_Gridview>)gv_SoldTo.DataSource;
                    IList<mdm_Sold_Gridview> sold1 = (mdm_Sold_Gridview.process == TaskAPI.Process & mdm_Sold_Gridview.incident == TaskAPI.Incident).List<mdm_Sold_Gridview>();
                    if (sold_1_s.Count == 1)
                    {

                        return;
                    }
                    sold_1_s.RemoveAt(gv_SoldTo.ChangedRowIndex == -1 || gv_SoldTo.ChangedRowIndex >= sold_1_s.Count ? sold_1_s.Count - 1 : gv_SoldTo.ChangedRowIndex);
                    bool flag3 = false;
                    foreach (mdm_Sold_Gridview sold_1 in sold1)
                    {

                        foreach (mdm_Sold_Gridview sold_2 in sold_1_s)
                        {
                            if (sold_2.ID == sold_1.ID)
                            {
                                flag3 = true;
                                break;
                            }
                        }
                        if (!flag3)
                        {
                            Storage.Delete(sold_1);
                        }
                        flag3 = false;
                    }
                    gv_SoldTo.DataSource = sold_1_s;
                    gv_SoldTo.DataBind();
                    break;

                case "Sales_Delete":
                 
                    List<mdm_Sales_Gridview> sales_1_s = (List<mdm_Sales_Gridview>)gv_SalesOffice.DataSource;
                    IList<mdm_Sales_Gridview> sales1 = (mdm_Sales_Gridview.process == TaskAPI.Process & mdm_Sales_Gridview.incident == TaskAPI.Incident).List<mdm_Sales_Gridview>();
                    if (sales_1_s.Count == 1)
                    {

                        return;
                    }
                    sales_1_s.RemoveAt(gv_SalesOffice.ChangedRowIndex == -1 || gv_SalesOffice.ChangedRowIndex >= sales_1_s.Count ? sales_1_s.Count - 1 : gv_SalesOffice.ChangedRowIndex);
                    bool flag4 = false;
                    foreach (mdm_Sales_Gridview sales_1 in sales1)
                    {

                        foreach (mdm_Sales_Gridview sold_2 in sales_1_s)
                        {
                            if (sold_2.ID == sales_1.ID)
                            {
                                flag4 = true;
                                break;
                            }
                        }
                        if (!flag4)
                        {
                            Storage.Delete(sales_1);
                        }
                        flag4 = false;
                    }
                    gv_SalesOffice.DataSource = sales_1_s;
                    gv_SalesOffice.DataBind();
                    break;

                case "Region_Delete":

                    List<mdm_Regoion_Gridview> region_1_s = (List<mdm_Regoion_Gridview>)gv_Region.DataSource;
                    IList<mdm_Regoion_Gridview> region1 = (mdm_Regoion_Gridview.process == TaskAPI.Process & mdm_Regoion_Gridview.incident == TaskAPI.Incident).List<mdm_Regoion_Gridview>();
                    if (region_1_s.Count == 1)
                    {

                        return;
                    }
                    region_1_s.RemoveAt(gv_Region.ChangedRowIndex == -1 || gv_Region.ChangedRowIndex >= region_1_s.Count ? region_1_s.Count - 1 : gv_Region.ChangedRowIndex);
                    bool flag5 = false;
                    foreach (mdm_Regoion_Gridview region_1 in region1)
                    {

                        foreach (mdm_Regoion_Gridview region_2 in region_1_s)
                        {
                            if (region_2.ID == region_1.ID)
                            {
                                flag5 = true;
                                break;
                            }
                        }
                        if (!flag5)
                        {
                            Storage.Delete(region_1);
                        }
                        flag5 = false;
                    }
                    gv_Region.DataSource = region_1_s;
                    gv_Region.DataBind();
                    break;
            }
        }
        #endregion

        #region 方法 gv_City 数据取得
        protected void gv_City_DataBinding(object sender, EventArgs e)
        {
            //if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit && gv_CCC_1.ChangedColumnIndex == 9)
            if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit && (gv_City.ChangedColumnIndex == 1 || gv_City.ChangedColumnIndex == 2))
            {
                List<mdm_City_Gridview> ccc_s = gv_City.DataSource as List<mdm_City_Gridview>;

                foreach (mdm_City_Gridview ccc in ccc_s)
                {
                    m_MaterialDetermantion_CityName ncc = (m_MaterialDetermantion_CityName.city_Name == ccc.City_Name).ListFirst<m_MaterialDetermantion_CityName>();
                    if (ncc != null)
                    {
                        ccc.City_Code= ncc.City_Code;
                    }
                    else
                    {
                        ccc.City_Code = "";
                    }
                }
            }
        }
        #endregion
        
        #region 方法 数据验证
        private List<string> DataValidation()
        {
            #region VD
            List<Regular> regs = new List<Regular>();
            //if (VD.Checked && SA.Checked ) { regs.Add(new Regular(RegularExp.NotEmpty, "", "material: 选择了Employee 则不能选material")); }
            if (VD.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty,National_Division.SelectedValue , " National: Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, National_Valid_From.Text, " National: Valid From 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, National_Valid_To.Text, " National: Valid To 必填"));

                foreach (mdm_National_Gridview National in (List<mdm_National_Gridview>)gv_National.DataSource)
                {
                    if (string.IsNullOrEmpty(National.National_Material_From) && string.IsNullOrEmpty(National.National_Material_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(National.National_Material_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, National.National_Material_From, "&nbsp;&nbsp;行" + National.No + ": National: Material From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(National.National_Material_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, National.National_Material_To, "&nbsp;&nbsp;行" + National.No + ": National: Material To 为必填 "));
                    }
                }
            }
            #endregion

            #region SA
            if (SA.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, City_Division.SelectedValue, " City: Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, City_Valid_From.Text, " City: Valid From 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, City_Valid_To.Text, " City: Valid To 必填"));

                regs.Add(new Regular(RegularExp.NotEmpty, (!All_City.Checked && !Some_City.Checked ? "" : "NotBlank"), "City:  1.All City 或 2.Some City 至少需要选择 1 个"));


                foreach (mdm_City_Gridview City in (List<mdm_City_Gridview>)gv_City.DataSource)
                {
                    if (string.IsNullOrEmpty(City.City_Material_From) && string.IsNullOrEmpty(City.City_Material_To))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(City.City_Material_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, City.City_Material_From, "&nbsp;&nbsp;行" + City.No + ": City: Material From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(City.City_Material_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, City.City_Material_To, "&nbsp;&nbsp;行" + City.No + ": City: Material To 为必填 "));
                    }

                    //if (Some_City.Checked)
                    //{
                    //    regs.Add(new Regular(RegularExp.NotEmpty, City.City_Name, "&nbsp;&nbsp;行" + City.No + ": City: City Name 为必填 "));
                    //}
                }

                if (Some_City.Checked)
                {
                    foreach (mdm_City_Gridview City in (List<mdm_City_Gridview>)gv_City.DataSource)
                    {
                        if (string.IsNullOrEmpty(City.City_Material_From) && string.IsNullOrEmpty(City.City_Material_To))
                        {
                            continue;
                        }

                        
                        if (Some_City.Checked)
                        {
                            regs.Add(new Regular(RegularExp.NotEmpty, City.City_Name, "&nbsp;&nbsp;行" + City.No + ": City: City Name 为必填 "));
                        }
                    }
                }



            }
            #endregion

            #region SA2
            if (SA2.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Sold_Division.SelectedValue, " Sold to: Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Sold_Valid_From.Text, " Sold to: Valid From 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Sold_Valid_To.Text, " Sold to: Valid To 必填"));

                foreach (mdm_Sold_Gridview Sold in (List<mdm_Sold_Gridview>)gv_SoldTo.DataSource)
                {
                    if (string.IsNullOrEmpty(Sold.Sold_Material_From) && string.IsNullOrEmpty(Sold.Sold_Material_To) && string.IsNullOrEmpty(Sold.Sold_To_Party))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(Sold.Sold_To_Party))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Sold.Sold_To_Party, "&nbsp;&nbsp;行" + Sold.No + ": Sold to: Sold-to party 为必填 "));
                    }

                    if (string.IsNullOrEmpty(Sold.Sold_Material_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Sold.Sold_Material_From, "&nbsp;&nbsp;行" + Sold.No + ": Sold to: Material From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(Sold.Sold_Material_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Sold.Sold_Material_To, "&nbsp;&nbsp;行" + Sold.No + ": Sold to: Material To 为必填 "));
                    }

                   

                   
                }
            }
            #endregion

            #region SA3
            if (SA3.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Sales_Division.SelectedValue, " Sales Office: Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Sales_Valid_From.Text, " Sales Office: Valid From 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Sales_Valid_To.Text, " Sales Office: Valid To 必填"));

                foreach (mdm_Sales_Gridview Sales in (List<mdm_Sales_Gridview>)gv_SalesOffice.DataSource)
                {
                    if (string.IsNullOrEmpty(Sales.Sales_Material_From) && string.IsNullOrEmpty(Sales.Sales_Material_To) && string.IsNullOrEmpty(Sales.Sales_To_Party))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(Sales.Sales_To_Party))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Sales.Sales_To_Party, "&nbsp;&nbsp;行" + Sales.No + ": Sales Office: Sales Office 为必填 "));
                    }
                    
                    if (string.IsNullOrEmpty(Sales.Sales_Material_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Sales.Sales_Material_From, "&nbsp;&nbsp;行" + Sales.No + ": Sales Office: Material From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(Sales.Sales_Material_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Sales.Sales_Material_To, "&nbsp;&nbsp;行" + Sales.No + ": Sales Office: Material To 为必填 "));
                    }
                }

            }
            #endregion

            #region SA4
            if (SA4.Checked)
            {
                regs.Add(new Regular(RegularExp.NotEmpty, Region_Division.SelectedValue, " Region: Division 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Region_Valid_From.Text, " Region: Valid From 必填"));
                regs.Add(new Regular(RegularExp.NotEmpty, Region_Valid_To.Text, " Region: Valid To 必填"));

                foreach (mdm_Regoion_Gridview Region in (List<mdm_Regoion_Gridview>)gv_Region.DataSource)
                {
                    if (string.IsNullOrEmpty(Region.Region_Material_From) && string.IsNullOrEmpty(Region.Region_Material_To) && string.IsNullOrEmpty(Region.Region))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(Region.Region))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Region.Region, "&nbsp;&nbsp;行" + Region.No + ": Region: Region 为必填 "));
                    }

                    if (string.IsNullOrEmpty(Region.Region_Material_From))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Region.Region_Material_From, "&nbsp;&nbsp;行" + Region.No + ": Region: Material From 为必填 "));
                    }

                    if (string.IsNullOrEmpty(Region.Region_Material_To))
                    {
                        regs.Add(new Regular(RegularExp.NotEmpty, Region.Region_Material_To, "&nbsp;&nbsp;行" + Region.No + ": Region: Material To 为必填 "));
                    }
                }

            }
            #endregion


       

            return Validation(regs);
        }
        #endregion

        #region 方法 Others
        protected void VD_Payment_Methods_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }
        private string getFormCheckList(Anthem .CheckBoxList ck)
        {
            string t = "";
            for (int i = 0; i < ck.Items.Count; i++)
                if (ck.Items[i].Selected)
                    t += "," + ck.Items[i].Value;
                else
                    t += ",";
            return t;
        }
        private Anthem.CheckBoxList setCheckList(string t, Anthem .CheckBoxList ck)
        {
            try
            {
                string[] tt = t.Split(',');

                for (int i = 0; i <= tt.GetUpperBound(0); i++)
                {
                    for (int j = 0; j < ck.Items.Count; j++)
                    {
                        if (ck.Items[j].Value == tt[i].ToString())
                        { ck.Items[j].Selected = true; break; }
                    }
                }
            }
            catch { }
            return ck;
        }
        #endregion

        #region 方法 All_City
        protected void All_City_CheckedChanged(object sender, EventArgs e)
        {
            switch (((Anthem.CheckBox)sender).ID)
            {
                case "All_City":

                    if (All_City.Checked)
                    {
                        Some_City.Checked = false;
                    }
                    All_City.Checked = !Some_City.Checked;

                    break;

                case "Some_City":
                    if (Some_City.Checked)
                    {
                        All_City.Checked = false;
                    }
                    Some_City.Checked = !All_City.Checked;

                    break;
            }
        }
        #endregion

    }
}